package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class BocDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {

		STATE.put("0000", "Congratulations ,payment successful");// 成功
		STATE.put("1000", "please wait ,transaction is on going"); // 交易处理中
		STATE.put("1001", "system is repairing");// 系统维护中，暂停交易
		STATE.put("1102", "data length error");// 数据字段长度不符合定义
		STATE.put("1103", "Merchant has not opened");// 商户未开通
		STATE.put("1104", "Access code error");// 接入码错误
		STATE.put("1105", "No checkout transaction");// 无结账交易
		STATE.put("1106", "The merchant number does not exist");// 该商户号不存在
		STATE.put("1107", "Trading channel is not open");// 交易通道未开通
		STATE.put("3301", "There are required fields not giving");// 存在必填字段未上送
		STATE.put("3302", "transaction type not accept");// 信用卡交易的种类
		STATE.put("3304", "Currency trading error");// 交易币种错误
		STATE.put("3305", "Cards transactions types not opened");// 信用卡交易的种类
		STATE.put("3306", "Transaction amount is greater than the tradable");// 交易金额超过了信用卡可交易的金额
		STATE.put("3307", "EDC transaction can not use DCC Number");// EDC交易不能使用DCC编号
		STATE.put("3308", "Complete the pre-authorized amount exceeds the authorized amount");// 授权完成金额超出预授权金额
		STATE.put("3309", "Mainframe overtime");// 主机超时
		STATE.put("3310", "Ticket number already exists");// 票据号已存在
		STATE.put("3311", "Field does not meet the requirements");// 字段不符合要求
		STATE.put("3312", "Invalid terminal");// 无效终端
		STATE.put("3313", "Gateway Type fill in error");// 网关类型填写错误
		STATE.put("3314", "Order_no already exists");// Order_no已存在
		STATE.put("3315", "DCC transaction ID can not be used EDC");// DCC交易不能使用EDC编号
		STATE.put("3316", "DCC DCC transaction does not match Exchange Rates");// DCC交易未能匹配DCC汇率查询
		STATE.put("3317", "Authorization number has been used, the request is denied");// 授权号已被使用，请求被拒绝
		STATE.put("3318", "Transaction / authorization has been revoked, the request is denied");// 交易/授权已撤销,请求被拒绝
		STATE.put("3319", "Ticket number can not be all zeros");// 票据号不能全为0
		STATE.put("3320", "Refund Amount over than Deal Amount");// 退款金额大于可退金额
		STATE.put("3321", "DCC transaction field to send a non-DCC trading ban");// 非DCC交易禁止上送DCC交易字段
		STATE.put("3322", "Card transactions exceeds the upper limit");// 卡交易次数超过上限
		STATE.put("3323", "Business card chargeback blacklist");// 商务卡黑名单拒付
		STATE.put("3324", "Merchant chargeback blacklist");// 商户黑名单拒付
		STATE.put("3325", "Global blacklist of dishonor");// 全局黑名单拒付
		STATE.put("3123", "Miscellaneous Shidehara transaction currency code is incorrect");// 杂币原交易货币代码不正确
		STATE.put("3124", "Miscellaneous currency trading card cardbin a problem");// 杂币交易卡号cardbin有问题
		STATE.put("3125", "Miscellaneous incorrectly formatted currency amount");// 杂币金额格式不正确
		STATE.put("3126", "VISA card merchant daily transaction amount exceeds the upper limit");// 商户VISA卡每日交易笔数超过上限
		STATE.put("3127", "The merchant VISA card daily trading accumulative amount exceeds the limit");// 商户VISA卡每日交易累计金额超过上限
		STATE.put("3128", "VISA card merchant gateway daily transaction amount exceeds the upper limit");// 网关商户VISA卡每日交易笔数超过上限
		STATE.put("3129", "VISA card merchant gateway cumulative amount exceeds the daily trading limit");// 网关商户VISA卡每日交易累计金额超过上限
		STATE.put("3226", "MASTERCARD card merchant daily transaction amount exceeds the upper limit");// 商户MASTERCARD卡每日交易笔数超过上限
		STATE.put("3227", "MASTERCARD merchant card transactions daily cumulative amount exceeds the upper limit");// 商户MASTERCARD卡每日交易累计金额超过上限
		STATE.put("3228", "MASTERCARD card merchant gateway daily transaction amount exceeds the upper limit");// 网关商户MASTERCARD卡每日交易笔数超过上限
		STATE.put("3229", "MASTERCARD card merchant gateway daily cumulative amount of the transaction exceeds the upper limit");// 网关商户MASTERCARD卡每日交易//
																																	// 累计金额超过上限
		STATE.put("3326", "The merchant JCB card daily transaction number exceeds the upper limit");// 商户JCB卡每日交易笔数超过上限
		STATE.put("3327", "The merchant JCB card daily trading accumulative amount exceeds the limit");// 商户JCB卡每日交易累计金额超过上限
		STATE.put("3328", "MASTERCARD Gateway merchant JCB card maximum number of daily transactions");// 网关商户JCB卡每日交易笔数超过上限
		STATE.put("3329", "JCB card merchant gateway cumulative amount exceeding the daily trading limit");// 网关商户JCB卡每日交易累计金额超过上限
		STATE.put("3350", "There is an error in your transaction information Transaction failed");// 本次交易有错误信息
		STATE.put("3331", "3D return to the field is wrong");// 3D返回字段有误
		STATE.put("3336", "Unable to get the details of the original 3D related transactions");// 无法获取原始3D交易相关的明细
		STATE.put("3341", "Risk Returns wrong field");// Risk返回字段有误
		STATE.put("4001", "Jump cardholder timeout");// 持卡人跳转超时
		STATE.put("4002", "3D verification issuer return timeout");// 3D验证发卡行返回超时
		STATE.put("4403", "Wind control review timeout");// 风控review超时
		STATE.put("4401", "Trade has been in existence");// 交易已存在
		STATE.put("4402", "Unable to match the original transaction");// 无法匹配原始交易
		STATE.put("4404", "Valid entry error");// 有效期输入有误
		STATE.put("5501", "The Mpi ve connection exception");// Mpi ve连接异常
		STATE.put("5502", "The Mpi acs connection exception");// Mpi acs连接异常
		STATE.put("5503", "Mpi ve connection timeout");// Mpi ve连接超时
		STATE.put("5504", "Mpi acs connection timeout");// Mpi acs连接超时
		STATE.put("5505", "Mpi ve failed");// Mpi ve失败
		STATE.put("5506", "Mpi acs failure");// Mpi acs失败
		STATE.put("5507", "Mpi 3D validation error");// Mpi 3D验证过程错误
		STATE.put("5600", "Wind control success");// 风控成功
		STATE.put("5601", "Risk control requires review");// 风控需要进行review
		STATE.put("5602", "risk control refuse");// 信用卡有效期输入不正确
		STATE.put("5603", "risk control error");// 信用卡有效期输入不正确
		STATE.put("5699", "Ex-post risk control");// 进行事后风控
		STATE.put("9901", "Check issuer");// 查發卡行
		STATE.put("9902", "Check issuer");// 查發卡行
		STATE.put("9903", "Invalid merchant");// 無效商戶
		STATE.put("9904", "Confiscate the card");// 沒收卡
		STATE.put("9905", "Transaction failed . Please try again later or contact your card-issuing bank .");// 联系不到发卡行
		STATE.put("9906", "Merchant configuration exception");// 联系不到发卡行 本次交易失败
		STATE.put("9907", "Confiscate the card under special conditions");// 特殊條件下沒收卡
		STATE.put("9912", "Invalid transaction");// 無效交易
		STATE.put("9913", "Invalid amount");// 無效金額
		STATE.put("9914", "Invalid card number");// 無效卡號
		STATE.put("9915", "Invalid card issuers");// 本次交易没有查询得到发卡行
		STATE.put("9919", "Re-enter the transaction");// 重新輸入交易
		STATE.put("9930", "format error");// 格式錯誤
		STATE.put("9933", "Expired card");// 過期的卡
		STATE.put("9934", "Cheating suspected");// 有作弊嫌疑
		STATE.put("9935", "Merchants need to contact closed security line");// 商戶需與收單行保安部門聯系
		STATE.put("9936", "Restricted card");// 交易信用卡受到发卡行限制，不允许做交易
		STATE.put("9937", "Merchants call to receive special security services");// 商戶呼收單行保安部門
		STATE.put("9938", "Excess Inkyo specific PIN attempts import");// 超過允許的PIN試輸入
		STATE.put("9939", "Without the credit card account");// 無此信用卡賬戶
		STATE.put("9941", "Reported for loss card");// 信用卡已被挂失
		STATE.put("9943", "Stolen card");// 被盗窃的信用卡
		STATE.put("9951", "Without enough deposit");// 無足够的存款
		STATE.put("9954", "Expired card");// 過期的卡
		STATE.put("9955", "Excess Inkyo specific PIN attempts import");// 不正確的PIN
		STATE.put("9957", "Do not allow cardholders to deal");// 发卡行不允许持卡人进行交易
		STATE.put("9958", "Do not allow the terminal for trading");// 不允許終端進行的交易
		STATE.put("9959", "Cheating suspected");// 有作弊嫌疑
		STATE.put("9960", "Merchants to contact security");// 商戶與保安部聯系
		STATE.put("9961", "Beyond the amount limit");// 超出取款金額限制
		STATE.put("9962", "Restricted card");// 信用卡受到发卡行限制不允许本次交易
		STATE.put("9963", "Violation safety hermetically provisions");// 違反安全保密規定
		STATE.put("9965", "Card issuers bank refuse");// 違反安全保密規定
		STATE.put("9966", "Merchants call to receive the security line");// 商戶呼收單行保安部
		STATE.put("9970", "Undefine Error,Please contact the issuing bank");// 商戶呼收單行保安部
		STATE.put("9975", "Mascotas para introducir el número PIN invadido");// 允許的輸入PIN次數超限
		STATE.put("9976", "Please contact the issuing bank");// 請聯絡發卡銀行
		STATE.put("9977", "Amount of money mistake");// 金額錯誤
		STATE.put("9978", "Unknown mistake");// 金額錯誤
		STATE.put("9989", "Terminal code wrong");// 終端機代號錯
		STATE.put("9991", "Issuer or switching center can not operate");// 發卡行或交換中心不能操作
		STATE.put("9992", "Financial institution or intermediary network facilities can not be found or could not be reached");// 金融機構或中間網絡設施找不到或
		STATE.put("9993", "Trading is illegal, you can't accomplish");// 交易違法，不能完成
		STATE.put("9994", "Repeat trade");// 重覆交易
		STATE.put("9995", "Regulation refrain system complex");// 調節控制錯
		STATE.put("9996", "System failure");// 系統失效
		STATE.put("9998", "Exchange centre not get card issuers response");// 交換中心收不到發卡行應答
		STATE.put("9999", "PIN wrong format");// PIN 格式錯
		STATE.put("99XX", "Can not support transaction");// 发卡行不支持本次交易
		STATE.put("99YX", "Card Bin not allow DCC transaction");// 卡本不允许DCC事务
		STATE.put("99YY", "Card Bin allow DCC transaction");// 卡本允许DCC事务
		STATE.put("99YZ", "YZ dual-currency card to refusal of payment");// YZ
		STATE.put("99N7", "CVV verify error,the transaction failed");// CVV输入不正确，本次交易失败

		RISK.put("5602", "5602");
		RISK.put("9904", "9904");
		RISK.put("9933", "9933");
		RISK.put("9939", "9939");
		RISK.put("9941", "9941");
		RISK.put("9943", "9943");
		RISK.put("9954", "9954");
		RISK.put("9907", "9907");
		RISK.put("9958", "9958");
		RISK.put("9959", "9959");
		RISK.put("9960", "9960");

		ALERT.put("555", 0L);

		HIDE.put("9905", 0L);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}

	public static synchronized void warning(String code, int limit) {
		String name = "BOC";
		String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
		if (ALERT.containsKey(code)) {
			ALERT.put(code, ALERT.get(code)+1);
			if (new Integer(ALERT.get(code).toString()) > limit) {
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time + "]" + name + "返回码[" + code + "]超过[" + limit + "]次");
			}
		}
	}

}
